package com.ls.guava;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;

public class GuavaTest {
	public static void main(String[] args) {
		testOption();
	}

	private static <T, V> void testBasic() {
		List<Map<String, Object>> maps = Lists.newArrayList();
		List<String> langs = Lists.newArrayList("中文", "English", "日本語", null);
		String lang = Joiner.on("|").useForNull("空值啦").join(langs);
		// 中文|English|日本語|Unkown
		System.out.println(lang);
		Map a = new HashMap<T,V>();
		// Like Map< Job, Collection< Employee > >
		Multimap<String, Employee> multimap = ArrayListMultimap.create();
		multimap.put("CEO", new Employee("Tom", 45));
		multimap.put("DESIGNER", new Employee("Jack", 24));
		multimap.put("DEVELOPER", new Employee("Alice", 31));
		multimap.put("DEVELOPER", new Employee("Jhone", 25));
		multimap.put("DEVELOPER", new Employee("Jim", 27));
		Collection<Employee> ems = multimap.get("DEVELOPER");
		for (Employee e : ems) {
			System.out.println(e.toString());
		}
	}

	public static void testNull() {
		int age = 0;
		System.out.println("user age:" + age);

		long money;
		money = 10L;
		System.out.println("user money" + money);

		String name = null;
		System.out.println("user name:" + name);
	}

	public static void testOption() {
		Optional<Integer> possible = Optional.of(6);
		Optional<Integer> absentOpt = Optional.absent();
		Optional<Integer> NullableOpt = Optional.fromNullable(null);
		Optional<Integer> NoNullableOpt = Optional.fromNullable(10);
		if (possible.isPresent()) {
			System.out.println("possible isPresent:" + possible.isPresent());
			System.out.println("possible value:" + possible.get());
		}
		if (absentOpt.isPresent()) {
			System.out.println("absentOpt isPresent:" + absentOpt.isPresent());
		}
		if (NullableOpt.isPresent()) {
			System.out.println("fromNullableOpt isPresent:" + NullableOpt.isPresent());
		}
		if (NoNullableOpt.isPresent()) {
			System.out.println("NoNullableOpt isPresent:" + NoNullableOpt.isPresent());
		}
	}
}
